﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.TournamentGames.TournamentGame
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.TournamentGames
{
  public abstract class TournamentGame
  {
    [SaveableField(60)]
    protected int _lastRecordedLordCountForTournamentPrize;

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this.Town);
      CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime((object) this.CreationTime, collectedObjects);
      collectedObjects.Add((object) this.Prize);
    }

    internal static object AutoGeneratedGetMemberValueTown(object o)
    {
      return (object) ((TournamentGame) o).Town;
    }

    internal static object AutoGeneratedGetMemberValueCreationTime(object o)
    {
      return (object) ((TournamentGame) o).CreationTime;
    }

    internal static object AutoGeneratedGetMemberValueMode(object o)
    {
      return (object) ((TournamentGame) o).Mode;
    }

    internal static object AutoGeneratedGetMemberValuePrize(object o)
    {
      return (object) ((TournamentGame) o).Prize;
    }

    internal static object AutoGeneratedGetMemberValue_lastRecordedLordCountForTournamentPrize(
      object o)
    {
      return (object) ((TournamentGame) o)._lastRecordedLordCountForTournamentPrize;
    }

    [SaveableProperty(10)]
    public Town Town { get; private set; }

    [SaveableProperty(20)]
    public CampaignTime CreationTime { get; private set; }

    [SaveableProperty(30)]
    public TournamentGame.QualificationMode Mode { get; protected set; }

    public virtual int MaxTeamSize => 1;

    public virtual int MaxTeamNumberPerMatch => 2;

    [SaveableProperty(40)]
    public ItemObject Prize { get; private set; }

    public virtual float TournamentWinRenown
    {
      get
      {
        return (float) Campaign.Current.Models.TournamentModel.GetRenownReward(Hero.MainHero, this.Town);
      }
    }

    public virtual float TournamentWinInfluence
    {
      get
      {
        return (float) Campaign.Current.Models.TournamentModel.GetInfluenceReward(Hero.MainHero, this.Town);
      }
    }

    public abstract int RemoveTournamentAfterDays { get; }

    public abstract int MaximumParticipantCount { get; }

    public abstract TextObject GetMenuText();

    public abstract void OpenMission(Settlement settlement, bool isPlayerParticipating);

    public abstract MBList<CharacterObject> GetParticipantCharacters(
      Settlement settlement,
      bool includePlayer = true);

    protected abstract ItemObject GetTournamentPrize(
      bool includePlayer,
      int lastRecordedLordCountForTournamentPrize);

    protected TournamentGame(Town town, ItemObject prize = null)
    {
      this.Town = town;
      this.Prize = prize ?? this.GetTournamentPrize(false, this._lastRecordedLordCountForTournamentPrize);
      this.CreationTime = CampaignTime.Now;
      this._lastRecordedLordCountForTournamentPrize = 0;
    }

    public virtual bool CanBeAParticipant(CharacterObject character, bool considerSkills) => true;

    public void PrepareForTournamentGame(bool isPlayerParticipating)
    {
      this.OpenMission(Settlement.CurrentSettlement, isPlayerParticipating);
    }

    public void UpdateTournamentPrize(bool includePlayer, bool removeCurrentPrize = false)
    {
      if (removeCurrentPrize)
        this.Prize = (ItemObject) null;
      this.Prize = this.GetTournamentPrize(includePlayer, this._lastRecordedLordCountForTournamentPrize);
    }

    public enum QualificationMode
    {
      IndividualScore,
      TeamScore,
    }
  }
}
